package org.android.brasil.projetos.oktoberfest2011.utils;

import java.util.Calendar;

import org.android.brasil.projetos.oktoberfest2011.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.widget.TextView;

public class ControleDeBackground {

	private static int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

	private static String corParFundoPassado;
	private static String corParTextoPassado;

	private static String corImparFundoPassado;
	private static String corImparTextoPassado;

	private static String corFundoHoje;
	private static String corTextoHoje;

	private static String corParFundoFuturo;
	private static String corParTextoFuturo;

	private static String corImparFundoFuturo;
	private static String corImparTextoFuturo;

	private static String corSeparatorVertial;

	public static void setBackgroundAgenda(View[] views, View separatorVertial, TextView[] tvs,
			int posicao, int dia) {

		day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

		/*
		 * corParFundoPassado = "#DFDFDF"; corParTextoPassado = "#000000";
		 * 
		 * corImparFundoPassado = "#DFDFDF"; corImparTextoPassado = "#000000";
		 */
		corParFundoPassado = "#BFBFBF";
		corParTextoPassado = "#000000";

		corImparFundoPassado = "#DFDFDF";
		corImparTextoPassado = "#000000";

		corFundoHoje = "#FFFFFF";
		corTextoHoje = "#000000";

		//corParFundoFuturo = "#FDD1A1";
		corParFundoFuturo = "#FFD3A5";
		
		corParTextoFuturo = "#000000";

		corImparFundoFuturo = "#FFFFFF";
		corImparTextoFuturo = "#000000";

		corSeparatorVertial = "#3BCF4E";
		//corSeparatorVertial = "#000000";

		if (separatorVertial != null) {
			separatorVertial.setBackgroundColor(Color.parseColor(corSeparatorVertial));
		}
		setColors(views, tvs, posicao, dia);
	}

	public static void setBackgroundHorario(View[] views, TextView[] tvs, int posicao, int dia) {

		day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

		corParFundoPassado = "#BFBFBF";
		corParTextoPassado = "#000000";

		corImparFundoPassado = "#DFDFDF";
		corImparTextoPassado = "#000000";

		corFundoHoje = "#FDD1A1";
		corTextoHoje = "#FF0000";

		//corParFundoFuturo = "#FDD1A1";
		corParFundoFuturo = "#FFD3A5";
		corParTextoFuturo = "#000000";

		corImparFundoFuturo = "#FFFFFF";
		corImparTextoFuturo = "#000000";

		setColors(views, tvs, posicao, dia);
	}

	public static void setBackgroundTwitter(View[] views, TextView[] tvs, int posicao) {

		day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

		//corParFundoFuturo = "#FDD1A1";
		corParFundoFuturo = "#FFD3A5";
		corParTextoFuturo = "#000000";

		corImparFundoFuturo = "#FFFFFF";
		corImparTextoFuturo = "#000000";

		setColors(views, tvs, posicao);
	}

	private static void setColors(View[] views, TextView[] tvs, int posicao) {

		if (posicao % 2 == 0) {

			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corParFundoFuturo));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corParTextoFuturo));
			}

		}

		if (posicao % 2 != 0) {

			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corImparFundoFuturo));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corImparTextoFuturo));
			}

		}

	}

	private static void setColors(View[] views, TextView[] tvs, int posicao, int dia) {
		Boolean passado = false;
		if ((Calendar.getInstance().get(Calendar.MONTH) == Constantes.CALENDAR_MES_DA_OKTOBERFEST)
				&& (Calendar.getInstance().get(Calendar.YEAR) == Constantes.ANO_DA_OKTOBERFEST)) {
			if (dia < day) {
				passado = true;
			}
			if (dia > day) {
				passado = false;
			}
			if (dia == day) {
				passado = null;
			}
		}
		if ((passado != null) && (passado) && (posicao % 2 == 0)) {

			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corParFundoPassado));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corParTextoPassado));
			}

		}

		if ((passado != null) && (passado) && (posicao % 2 != 0)) {

			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corImparFundoPassado));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corImparTextoPassado));
			}

		}

		if (passado == null) {
			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corFundoHoje));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corTextoHoje));
			}

		}

		if ((passado != null) && (!passado) && (posicao % 2 == 0)) {
			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corParFundoFuturo));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corParTextoFuturo));
			}

		}

		if ((passado != null) && (!passado) && (posicao % 2 != 0)) {
			for (View v : views) {
				v.setBackgroundColor(Color.parseColor(corImparFundoFuturo));
			}

			for (TextView v : tvs) {
				v.setTextColor(Color.parseColor(corImparTextoFuturo));
			}

		}

	}

	/*
	 * public static void setBackground(View rl, TextView tv, int posicao, int
	 * dia) {
	 * 
	 * if (dia < day && posicao % 2 == 0) {
	 * rl.setBackgroundColor(Color.parseColor("#E4E4E4"));
	 * tv.setTextColor(Color.parseColor("#000000")); // SetGradient(v,
	 * 0xFF2ec947, // 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia < day && posicao % 2 != 0) {
	 * rl.setBackgroundColor(Color.parseColor("#B4B4B4"));
	 * tv.setTextColor(Color.parseColor("#000000")); // SetGradient(v,
	 * 0xFF2ec947, // 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia == day && posicao % 2 == 0) {
	 * rl.setBackgroundColor(Color.parseColor("#CC9999"));
	 * tv.setTextColor(Color.parseColor("#000000")); // SetGradient(v,
	 * 0xFF2ec947, // 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia == day && posicao % 2 != 0) {
	 * rl.setBackgroundColor(Color.parseColor("#FFFFFF"));
	 * tv.setTextColor(Color.parseColor("#000000")); // SetGradient(v,
	 * 0xFF2ec947, // 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia > day && posicao % 2 == 0) {
	 * rl.setBackgroundColor(Color.parseColor("#FDD1A1")); // SetGradient(v,
	 * 0xFFD74937, // 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia > day && posicao % 2 != 0) {
	 * rl.setBackgroundColor(Color.parseColor("#FFFFFF")); // SetGradient(v,
	 * 0xFFF7F9F7, // 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * }
	 */
	/*
	 * public static void setBackground(View v, int posicao, int dia,
	 * Apresentacao apr) { if (posicao % 2 == 0) { //
	 * v.setBackgroundColor(Color.GREEN); SetGradient(v, 0xFF2ec947, 0xFFFFFFFF,
	 * GradientDrawable.Orientation.LEFT_RIGHT); } else { //
	 * v.setBackgroundColor(Color.parseColor("#FDD1A1")); SetGradient(v,
	 * 0xFFFDD1A1, 0xFFFFFFFF, GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia < day) { // v.setBackgroundColor(Color.parseColor("#505050"));
	 * SetGradient(v, 0xFF505050,
	 * 0xFFFFFFFF,GradientDrawable.Orientation.LEFT_RIGHT); }
	 * 
	 * if (dia > day) { // TODO: Pensar em um meio de controlar a cor de fundo
	 * pela // hora..temos em um mesmo dia // horas de inicio do evento depois
	 * da meia noite.. // Gambiarra..ao inves de colocar 02:00 da manha..colocar
	 * 26:00 da // manha no banco. setBackground(v, posicao); } }
	 */

	public static void SetGradient(View v, int color1, int color2,
			GradientDrawable.Orientation orientation) {
		GradientDrawable gd = new GradientDrawable(orientation, new int[] { color1, color2 });
		gd.setCornerRadius(0f);
		v.setBackgroundDrawable(gd);
	}

	public static void SetBarraSuperiorBackGround(Context ctx, View v) {
		v.setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.backgroundbarra));
	}
	/*
	 * public static void SetGradient(View v) { int color1 =
	 * Color.parseColor("#AA3026"); int color2 = Color.parseColor("#FFFFFF");
	 * GradientDrawable.Orientation orientation =
	 * GradientDrawable.Orientation.BOTTOM_TOP; GradientDrawable gd = new
	 * GradientDrawable(orientation, new int[] { color1, color2 });
	 * gd.setCornerRadius(0f); v.setBackgroundDrawable(gd); }
	 */
}
